<template>
  <div>
    <el-alert
      style="background-color: #409EFF; color: #222222; font-style: unset; margin-top: 10px; margin-bottom: 20px"
      :closable="false" title="人员调动管理"/>
    <el-form style="margin-left: 5px" size="mini" :inline="true" class="demo-form-inline">
      <el-form-item label="审核状态" prop="reason" :label-width="formLabelWidth">
        <el-select v-model="searchForm.statu" >
          <el-option label="待审核" value="0"></el-option>
          <el-option label="通过" value="1"></el-option>
          <el-option label="不通过" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-refresh-right" @click="resetSearchForm">重置</el-button>
      </el-form-item>
    </el-form>
    <el-divider></el-divider>
    <el-dialog title="人员调用" :visible.sync="dialogFormVisible">
      <el-form :model="editForm" :rules="rules" ref="addForm">
        <el-form-item>
          <el-select v-model="editForm.statu" >
            <el-option label="待审核" value="0"></el-option>
            <el-option label="通过" value="1"></el-option>
            <el-option label="不通过" value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('addForm')">确 定</el-button>
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>

    <!--    <div class="table">-->
    <el-table class="content" tooltip-effect="dark" border
              :data="tableData" :header-cell-style="{'text-align':'center'}">
      <el-table-column prop="userVo.realName" label="申请人" align="center"/>
      <el-table-column prop="beforeDepartmentVo.name" label="当前部门" align="center"/>
      <el-table-column prop="afterDepartmentVo.name" label="申请部门"/>
      <el-table-column prop="personnelTransfer.createTime" label="申请时间" align="center"/>
      <el-table-column label="审批状态" align="center">
        <template slot-scope="scope">
          <el-tag type="success" size="small" plain v-if="scope.row.personnelTransfer.statu == '1'">同意</el-tag>
          <el-tag type="info" size="small" plain v-if="scope.row.personnelTransfer.statu == '0'">待审核</el-tag>
          <el-tag type="danger" size="small" plain v-if="scope.row.personnelTransfer.statu == '2'">不同意</el-tag>
        </template>
      </el-table-column>
            <el-table-column
              fixed="right"
              label="操作"
              v-if="hasAuth('views.personnel.personnelTransfer.personnelTransfer.update')"
              width="150px">
              <template slot-scope="scope">
                <el-button v-if="scope.row.personnelTransfer.statu == '0'" type="text" @click="editHandle(scope.row.personnelTransfer.id)">编辑</el-button>
              </template>
            </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="total, sizes, prev, pager, next, jumper"
      style="align-content: center; align-items: center; margin-left: 15px"
      :current-page="currentPage"
      :page-sizes="pageSizes"
      :total="totalCount"
      :page-size="PageSize"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    ></el-pagination>
  </div>
  <!--  </div>-->
</template>

<script>
import { validatePhone, isIntegerNotMust, isDecimal } from '@/utils/validator'

export default {
  name: 'employeeLeave',
  data() {
    return {
      dialogFormVisible: false,
      updateForm: false,
      //添加表单的数据
      tableData: [],
      // 默认显示第几页
      currentPage: 1,
      // 个数选择器（可修改）
      pageSizes: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
      // 总条数，根据接口获取数据长度(注意：这里不能为空)
      totalCount: 1,
      // 个数选择器（可修改）
      PageSize: 10,
      editForm: {},
      searchForm: {statu: '0'},
      formLabelWidth: '120px',
    }
  },

  mounted() {
    this.load();
    this.loadAllDepartment() //加载部门
  },

  methods: {
    editHandle(id) {
      this.axios.get('/personnelTransfer/info/' + id).then(res => {
        this.editForm = res.data
        this.dialogFormVisible = true
      })
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.axios.post('/personnelTransfer/' + (this.editForm.id ? 'update' : 'add'), this.editForm).then(resp => {
            if (resp.code === 200) {
              this.$message({
                message: '操作成功',
                type: 'success',
                onClose: () => { //关闭回调
                }
              })
              this.load()
              this.dialogFormVisible = false
              this.editForm = {}
            }
          })
        }
      })
    },
    handleSizeChange(val) {
      this.PageSize = val
      this.currentPage = 1
    },
    handleCurrentChange(val) {
      this.currentPage = val
    },
    search() {
      this.axios.post('/personnelTransfer/select', this.searchForm).then((resp) => {
          this.tableData = resp.data
          this.totalCount = resp.data.length
        }
      )
    },
    resetSearchForm() {
      this.searchForm = {}
      this.load()
    },
    load() {
      let param = {
        statu : '0',
      }
      this.axios.post('/personnelTransfer/select', param).then((resp) => {
          this.tableData = resp.data
          // if (resp.data != null) {
          //   this.totalCount = resp.data.length
          // }
        }
      )
    },

  }
}
</script>

<style scoped>
.table {
  border-radius: 5px;
  margin: 10px;
  background-color: #FAFAFA;
  /*text-align: center;*/
}

.content {
  -webkit-box-shadow: #666 0px 0px 10px;
  -moz-box-shadow: #666 0px 0px 10px;
  box-shadow: #666 0px 0px 10px;
  background: #EEFF99;

  /*margin-right: 15px;*/
  /*margin-left: 15px;*/
}

.el-table {
  border-radius: 5px;
  margin-right: 15px;
  margin-left: 15px;
  margin-bottom: 10px;
  width: 98%;
}
</style>
